
#include "GTWindow.h"
#include "GWindowMgr.h"

#define TOTALANIMATETIME 0.5f





void CGTWindow::show()
{
	hide();
	gtk_widget_show( window );

}

void CGTWindow::hide()
{
	gtk_widget_hide( window );
}

void CGTWindow::create(const char* bg_file )
{
	if ( NULL == bg_file )
		return;
	regWindow();

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
	gtk_widget_set_app_paintable(window, TRUE);
	gtk_widget_realize(window);

	GdkPixbuf *pixbuf1;
	GdkBitmap *bitmap1;
	GdkPixmap *pixmap1;


	pixbuf = gdk_pixbuf_new_from_file(bg_file, NULL);
	pixbuf1 = gdk_pixbuf_new_from_file("resource\\texture\\link_over.png", NULL);

	gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, &bitmap, 128);
	gdk_pixbuf_render_pixmap_and_mask(pixbuf1, &pixmap1, &bitmap1, 128);

	gtk_widget_shape_combine_mask(window, bitmap, 0, 0);
	//gtk_widget_shape_combine_mask(window, bitmap1, 175, 0);

	gdk_window_set_back_pixmap(window->window, pixmap, FALSE);


	//gtk_window_set_opacity(GTK_WINDOW(window), 0.7);

	m_pFixed = gtk_fixed_new ();
	gtk_widget_show (m_pFixed);
	gtk_container_add (GTK_CONTAINER (window), m_pFixed);


	g_object_unref(pixbuf);
	g_object_unref(bitmap);
	g_object_unref(pixmap);

	gtk_widget_show_all(window);

}

void CGTWindow::setPosition( int x, int y)
{
	gtk_widget_set_uposition( window, x, y);
}

void CGTWindow::setSize( int x, int y)
{
	gtk_widget_set_size_request (window, x, y);

}

CGPoint CGTWindow::getPosition()
{
	return CGPoint(0, 0);
}


CGPoint CGTWindow::size()
{
	return CGPoint(0, 0);
}

void CGTWindow::advanceTime( float fElaspedTime )
{
	//printf("%f\n", fElaspedTime);
	switch(m_eDState)
	{
	case E_HIDE:
		_updateHide(fElaspedTime);
		break;
	case E_SHOW:
		_updateShow(fElaspedTime);
	default:
		break;
	}

}

bool CGTWindow::isPari( GtkWidget *_pGw)
{
	if ( _pGw == window )
		return true;
	else
		return false;
	return false;
}

void CGTWindow::enabled()
{
	
}

void CGTWindow::disable()
{
	
}

void CGTWindow::updateLanguage()
{

}

void CGTWindow::showEX()
{
	if ( E_NORMAL != m_eDState )
		return;
	m_eDState = E_SHOW;
	m_fElaspedTime = 0.0f;
	show();
}

void CGTWindow::hideEX()
{
	if ( E_NORMAL != m_eDState )
		return;
	m_eDState = E_HIDE;
	m_fElaspedTime = 0.0f;

}

void CGTWindow::setAlpha( float fAlpha )
{
	m_fAlpha = fAlpha;
	gtk_window_set_opacity(GTK_WINDOW(window), fAlpha);

}

void CGTWindow::_updateShow( float fElaspedTime )
{
	if ( m_fElaspedTime < TOTALANIMATETIME )
	{
		m_fElaspedTime += fElaspedTime;
		float fAlpha = m_fElaspedTime / TOTALANIMATETIME;
		fAlpha *= 0.75;

		setAlpha( fAlpha );
	}
	else
	{
		m_eDState = E_NORMAL;

	}
}

void CGTWindow::_updateHide( float fElaspedTime )
{
	if ( m_fElaspedTime < TOTALANIMATETIME )
	{
		m_fElaspedTime += fElaspedTime;
		float fAlpha = (TOTALANIMATETIME - m_fElaspedTime) / TOTALANIMATETIME;
		fAlpha *= 0.75;

		setAlpha( fAlpha );
	}
	else
	{
		hide();
		m_eDState = E_NORMAL;

	}
}

